home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / mac / misc / update / tpasc302.cpt / TCL Update / New ArtClass Files / CArtClassApp.p < prev    next >
Encoding:
Text File  |  1990-05-11  |  9.3 KB  |  384 lines

  1. {****************************************************}
  2. {         CArtClassApp.p}
  3. {}
  4. {        The ArtClass Application Class}
  5. {}
  6. {        SUPERCLASS = CApplication}
  7. {}
  8. {        Copyright ⌐ 1989, Symantec Corporation.  All rights reserved.            }
  9. {}
  10. {        written by:                     Gregory H. Dow}
  11. {        ported from THINK C by:        Greg Howe}
  12. {}
  13. {****************************************************}
  14.  
  15. unit CArtClassApp;
  16.  
  17. interface
  18.  
  19.     uses
  20.         TCL, MoreTCL, ArtClassIntf;
  21.  
  22. implementation
  23.  
  24.  
  25. {****************************************************}
  26. { IArtClassApp}
  27. {}
  28. {        Initialize the ArtClass Application}
  29. {}
  30. {****************************************************}
  31.  
  32.     procedure CArtClassApp.IArtClassApp;
  33.         var
  34.             itemStr: Str255;
  35.  
  36.     begin
  37.         theAboutBox := nil;
  38.         gPaintTool := toolPENCIL;
  39.  
  40.         IApplication(4, 60000, 3072);    { Initialize superclass            }
  41.  
  42.                                         { Global variable for an offscreen    }
  43.                                         {   BitMap with its own port            }
  44.         new(gScratchPad);
  45.         gScratchPad.IBitMap(PNTG_WIDTH, PNTG_HEIGHT, TRUE);
  46.  
  47.         itsPatsDir.GetPattern(gPattern);
  48.         gLineSize := 1;
  49.  
  50.         gShapeCurs := GetCursor(CURSshape);
  51.         gPencilCurs := GetCursor(CURSpencil);
  52.         gEraserCurs := GetCursor(CURSeraser);
  53.         gBrushCurs := GetCursor(CURSbrush);
  54.         gDragCurs := GetCursor(CURSdrag);
  55.         gSelectCurs := GetCursor(CURSselect);
  56.  
  57.         gFontNum := applFont;
  58.         gFontSize := SYS_FONT_SIZE;
  59.         gFontStyle := [];
  60.         gLineSpacing := cmdSingleSpace;
  61.  
  62.         GetFontName(gFontNum, itemStr);
  63.         gFontItem := gBartender.FindItemText(MENUfont, itemStr);
  64.  
  65.         NumToString(gFontSize, itemStr);
  66.         gSizeItem := gBartender.FindItemText(MENUsize, itemStr);
  67.     end;
  68.  
  69.  
  70. {****************************************************}
  71. { MakeDesktop (OVERRIDE)}
  72. {}
  73. {        Use the Desktop subclass which supports floating windows}
  74. {}
  75. {****************************************************}
  76.  
  77.     procedure CArtClassApp.MakeDesktop;
  78.     begin
  79.         new(CFWDesktop(gDesktop));
  80.         CFWDesktop(gDesktop).IFWDesktop(SELF);
  81.     end;
  82.  
  83.  
  84. {****************************************************}
  85. { SetUpFileParameters (OVERRIDE)}
  86. {}
  87. {        Set parameters used by the Standard File Package}
  88. {}
  89. {****************************************************}
  90.  
  91.     procedure CArtClassApp.SetUpFileParameters;
  92.     begin
  93.         inherited SetUpFileParameters;    { Use defaults from superclass        }
  94.  
  95.         gSignature := 'Artì';                    { Signature for our application        }
  96.  
  97.         sfNumTypes := 1;
  98.         sfFileTypes[0] := 'PNTG';            { ArtClass can read paintings        }
  99.     end;
  100.  
  101.  
  102. {****************************************************}
  103. { SetUpMenus (OVERRIDE)}
  104. {}
  105. {        Set up the menus used by the Art Class Application}
  106. {}
  107. {****************************************************}
  108.  
  109.     procedure CArtClassApp.SetUpMenus;
  110.         var
  111.             macMenu: MenuHandle;
  112.             theToolsDir: CToolsDir;
  113.             thePatsDir: CPatternsDir;   { Altered by TCL Weaver 1.0 (5/9/90) }
  114.  
  115.     begin
  116.         new(theToolsDir);               { Director for a tear-off tool  menu }
  117.         itsToolsDir := theToolsDir;     { Altered by TCL Weaver 1.0 (5/9/90) }
  118.         itsToolsDir.IToolsDir(SELF);
  119.  
  120.         new(thePatsDir);                    { Tear-off Patterns menu        }
  121.         itsPatsDir := thePatsDir;           { Altered by TCL Weaver 1.0 (5/9/90) }
  122.         itsPatsDir.IPatternsDir(SELF);
  123.  
  124.         new(CBarOwner(gBartender));                { Use our own Bartender subclass    }
  125.         CBarOwner(gBartender).IBarOwner(MBARapp);
  126.  
  127.         AddResMenu(GetMHandle(MENUapple), 'DRVR');        { Apple Menu    }
  128.         gBartender.SetDimOption(MENUapple, dimNONE);
  129.  
  130.         AddResMenu(GetMHandle(MENUfont), 'FONT');
  131.  
  132.                                         { No individual items are ever    }
  133.                                         {   dimmed in these menus. It's    }
  134.                                         {   all or nothing                    }
  135.  
  136.         gBartender.SetDimOption(MENUtools, dimNONE);
  137.         gBartender.SetDimOption(MENUpatterns, dimNONE);
  138.         gBartender.SetDimOption(MENUlines, dimNONE);
  139.         gBartender.SetDimOption(MENUtext, dimNONE);
  140.         gBartender.SetDimOption(MENUfont, dimNONE);
  141.         gBartender.SetDimOption(MENUsize, dimNONE);
  142.  
  143.                                         { These menus have check marked    }
  144.                                         {   items                                }
  145.  
  146.         gBartender.SetUnchecking(MENUlines, TRUE);
  147.         gBartender.SetUnchecking(MENUtext, TRUE);
  148.         gBartender.SetUnchecking(MENUfont, TRUE);
  149.         gBartender.SetUnchecking(MENUsize, TRUE);
  150.     end;
  151.  
  152.  
  153. {****************************************************}
  154. { DoCommand (OVERRIDE)}
  155. {}
  156. {        Execute a command}
  157. {}
  158. {****************************************************}
  159.  
  160.     procedure CArtClassApp.DoCommand (theCommand: longint);
  161.         var
  162.             itemName: Str255;
  163.             number: longint;
  164.             aStyle: Style;
  165.             anAboutBox: CAboutBox;      { Altered by TCL Weaver 1.0 (5/9/90) }
  166.  
  167.     begin
  168.         if theCommand < 0 then
  169.             begin
  170.                 case HiWord(-theCommand) of
  171.  
  172.                     MENUtools: 
  173.                         begin
  174.                             gPaintTool := PaintTools(LoWord(-theCommand));
  175.                             itsToolsDir.SelectTool(integer(gPaintTool));
  176.                         end;
  177.  
  178.                     MENUpatterns: 
  179.                         begin
  180.                             itsPatsDir.SelectPattern(LoWord(-theCommand));
  181.                             itsPatsDir.GetPattern(gPattern);
  182.                         end;
  183.  
  184.                     MENUfont: 
  185.                         begin
  186.                             gBartender.GetCmdText(theCommand, itemName);
  187.                             gFontItem := LoWord(-theCommand);
  188.                             GetFontNumber(itemName, gFontNum);
  189.                         end;
  190.  
  191.                     MENUsize: 
  192.                         begin
  193.                             gBartender.GetCmdText(theCommand, itemName);
  194.                             StringToNum(itemName, number);
  195.                             gSizeItem := LoWord(-theCommand);
  196.                             gFontSize := number;
  197.                         end;
  198.  
  199.                     otherwise
  200.                         inherited DoCommand(theCommand);
  201.                 end;
  202.             end
  203.  
  204.         else
  205.             begin
  206.                 case theCommand of
  207.  
  208.                     cmdAbout: 
  209.                         begin
  210.                             new(anAboutBox);                { Altered by TCL Weaver 1.0 (5/9/90) }
  211.                             theAboutBox := anAboutBox;
  212.                             theAboutBox.IAboutBox(SELF);
  213.                             theAboutBox.Free;
  214.                             theAboutBox := nil;
  215.                             FlushEvents(mDownMask + mUpMask + keyDownMask + keyUpMask + autoKeyMask, 0);
  216.                         end;
  217.  
  218.                     cmdLineNone, cmdLineOne, cmdLineTwo, cmdLineThree, cmdLineFour: 
  219.                         gLineSize := theCommand - cmdLineNone;
  220.  
  221.                     cmdPlain: 
  222.                         gFontStyle := [];
  223.  
  224.                     cmdBold: 
  225.                         if bold in gFontStyle then
  226.                             gFontStyle := gFontStyle - [bold]
  227.                         else
  228.                             gFontStyle := gFontStyle + [bold];
  229.  
  230.                     cmdItalic: 
  231.                         if italic in gFontStyle then
  232.                             gFontStyle := gFontStyle - [italic]
  233.                         else
  234.                             gFontStyle := gFontStyle + [italic];
  235.  
  236.                     cmdUnderline: 
  237.                         if underline in gFontStyle then
  238.                             gFontStyle := gFontStyle - [underline]
  239.                         else
  240.                             gFontStyle := gFontStyle + [underline];
  241.  
  242.                     cmdOutline: 
  243.                         if outline in gFontStyle then
  244.                             gFontStyle := gFontStyle - [outline]
  245.                         else
  246.                             gFontStyle := gFontStyle + [outline];
  247.  
  248.                     cmdShadow: 
  249.                         if shadow in gFontStyle then
  250.                             gFontStyle := gFontStyle - [shadow]
  251.                         else
  252.                             gFontStyle := gFontStyle + [shadow];
  253.  
  254.                     cmdCondense: 
  255.                         if condense in gFontStyle then
  256.                             gFontStyle := gFontStyle - [condense]
  257.                         else
  258.                             gFontStyle := gFontStyle + [condense];
  259.  
  260.                     cmdExtend: 
  261.                         if extend in gFontStyle then
  262.                             gFontStyle := gFontStyle - [extend]
  263.                         else
  264.                             gFontStyle := gFontStyle + [extend];
  265.  
  266.                     cmdSingleSpace, cmd1HalfSpace, cmdDoubleSpace: 
  267.                         gLineSpacing := theCommand;
  268.  
  269.                     otherwise
  270.                         inherited DoCommand(theCommand);
  271.                 end;
  272.             end;
  273.     end;
  274.  
  275.  
  276. {****************************************************}
  277. { UpdateMenus (OVERRIDE)}
  278. {}
  279. {        Perform menu management tasks}
  280. {}
  281. {****************************************************}
  282.  
  283.     procedure CArtClassApp.UpdateMenus;
  284.     begin
  285.         inherited UpdateMenus;
  286.  
  287.         gBartender.CheckMarkCmd(gLineSize + cmdLineNone, TRUE);
  288.     end;
  289.  
  290.  
  291. {****************************************************}
  292. { CreateDocument (OVERRIDE)}
  293. {}
  294. {        Make a document in response to the "New" menu selection.}
  295. {}
  296. {****************************************************}
  297.  
  298.     procedure CArtClassApp.CreateDocument;
  299.         var
  300.             theDocument: CArtClassDoc;
  301.  
  302.     begin
  303.         new(theDocument);
  304.         theDocument.IArtClassDoc(SELF);
  305.         theDocument.NewFile;
  306.     end;
  307.  
  308.  
  309. {****************************************************}
  310. { OpenDocument (OVERRIDE)}
  311. {}
  312. {        Open an existing file and create a document object for displaying}
  313. {        information.}
  314. {}
  315. {****************************************************}
  316.  
  317.     procedure CArtClassApp.OpenDocument (macSFReply: SFReply);
  318.         var
  319.             theDocument: CArtClassDoc;
  320.  
  321.     begin
  322.         new(theDocument);
  323.         theDocument.IArtClassDoc(SELF);
  324.         theDocument.OpenFile(macSFReply);
  325.     end;
  326.  
  327.  
  328. {****************************************************}
  329. { SwitchToDA}
  330. {}
  331. {        A DA is becoming active}
  332. {}
  333. {****************************************************}
  334.  
  335.     procedure CArtClassApp.SwitchToDA;
  336.     begin
  337.         inherited SwitchToDA;
  338.  
  339.         gBartender.DisableMenu(MENUtools);
  340.         gBartender.DisableMenu(MENUpatterns);
  341.         gBartender.DisableMenu(MENUlines);
  342.         gBartender.DisableMenu(MENUtext);
  343.     end;
  344.  
  345.  
  346. {****************************************************}
  347. { SwitchFromDA}
  348. {}
  349. {        Our application is becoming active after a DA had been running}
  350. {}
  351. {****************************************************}
  352.  
  353.     procedure CArtClassApp.SwitchFromDA;
  354.     begin
  355.         inherited SwitchFromDA;
  356.  
  357.         gBartender.EnableMenu(MENUtools);
  358.         gBartender.EnableMenu(MENUpatterns);
  359.         gBartender.EnableMenu(MENUlines);
  360.         gBartender.EnableMenu(MENUtext);
  361.     end;
  362.  
  363.  
  364. {****************************************************}
  365. { OutOfMemory}
  366. {}
  367. {         A memory request cannot be satisfied. At this point, the rainy day}
  368. {         fund has been liquidated. This method disposes of the about box if }
  369. {        there is one, then calls the inherited method. }
  370. {}
  371. {****************************************************}
  372.  
  373.     function CArtClassApp.OutOfMemory (bytesNeeded: Size): longint;
  374.         var
  375.             temp: longint;
  376.  
  377.     begin
  378.         if theAboutBox <> nil then
  379.             theAboutBox.Free;
  380.         temp := inherited OutOfMemory(bytesNeeded);
  381.     end;
  382.  
  383.  
  384. end.